﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataExport.MySqlDAL;
using System.Data.Objects;

namespace DataExport.BLL
{
    public class MobileDao
    {
        private static MobileEntities _mobile;

        static MobileDao()
        {
            _mobile = DataFactory.GetInstance();
        }

        public static IEnumerable<string> GetMobile(List<int> AID, int minAge, int maxAge, int sex, int minFee, int maxFee)
        {
            var result = _mobile.Numbers.Where<number>(m => AID.Contains(m.AID));

            DateTime maxTime = DateTime.Now.AddYears(-minAge);
            result = (minAge == -1) ? result : result.Where<number>(m => m.birthday <= maxTime);

            DateTime minTime = DateTime.Now.AddYears(-maxAge);
            result = (maxAge == -1) ? result : result.Where<number>(m => m.birthday >= minTime);
            
            result = (sex == -1) ? result : result.Where<number>(m => m.sex == sex);
            
            result = (minFee == -1) ? result : result.Where<number>(m => m.fee >= minFee);
            
            result = (maxFee == -1) ? result : result.Where<number>(m => m.fee <= maxFee);

            return result.Select(r => r.mobile);
        }
    }
}
